package tech.daoxuan.web.aspect;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Date;

/**
 * 可以拿到handler方法的参数
 */
@Aspect
@Component
public class TimeAspect {
        Logger logger = LoggerFactory.getLogger(TimeAspect.class);

    @Around("execution(* tech.daoxuan.web.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint point) throws Throwable {

        long time = new Date().getTime();
        //获得方法参数的数组
        Object[] args = point.getArgs();
        Arrays.stream(args).forEach(o -> {
            logger.info(o.toString()+"------------");
        });
        logger.info("aspect is start ===");

        Object proceed = point.proceed();
        logger.info("time aspect 耗时"+(new Date().getTime()-time));


        logger.info("aspect is finsh ===");
        //proceed 这个 对象就是 方法的返回值
        return proceed;
    }

}
